﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace Shopping
{
    internal class Homework08
    {
        //作业8: 编写程序实现购物换购的活动

        static void Print(int[,] Price, string[] Commidity) 
        {
            for (int i = 0; i < Commidity.Length; i++)
            {
                if (i == 0)
                {
                    Console.WriteLine($"{i}:{Commidity[i]}");
                }
                else
                {
                    Console.WriteLine($"{i}: 满{Price[i, 0]}元,加{Price[i, 1]}元换购{Commidity[i]}");
                }
            }
        }

        static void Main(string[] args)
        {
            //键盘获取消费金额
            Console.WriteLine("请输入消费金额:");
            int Consumption = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("是否参加优惠换购活动:");
            //定义一个选择,用于确认换购的商品
            int Choose = 0;
            //定义一个标志,用于判断循环是否结束
            int flag = 0;
            //定义总消费金额
            int total_consumption = 0;
            //定义二维数组,用于存放换购物购商品活动的换购需满足的消费金额和需额外支付的金额
            int[,] Price = { { 0, 0 }, { 50, 2 }, { 100, 3 }, { 100, 10 }, { 200, 10 }, { 200, 20 } };
            //定义字符串数组,用于存放购物换购活动的商品
            string[] Commidity = { "不换购", "百事可乐饮料1瓶", "500ml可乐一瓶", "5公斤面粉", "1个苏波尔炒菜锅", "欧莱雅爽肤水一瓶" };
            //flag为0则退出循环,不为0则继续循环
            do 
            {
                //调用打印函数
                Print(Price, Commidity);
                Console.Write("请选择:");
                Choose = Convert.ToInt32(Console.ReadLine());
                if (Consumption > Price[Choose,0]) 
                {
                    total_consumption = Consumption + Price[Choose,1];
                    Console.WriteLine($"本次消费总金额: {total_consumption}");
                    if (Choose > 0)
                    Console.WriteLine($"成功换购: {Commidity[Choose]}");
                    flag = 0;
                }
                else
                {
                    Console.WriteLine("------------------");
                    Console.WriteLine("不满足要求");
                    Console.WriteLine("------------------");
                    flag = 1;
                }
            }while (flag != 0);
        }
    }
}
